package com.steam.xbcc.mq;

import com.steam.xbcc.domain.MediaFile;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

@Component
public class CourseMediaVideoPushProducer {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public boolean sendMessage(MediaFile mediaFile){
        Message<MediaFile> fileMessage = MessageBuilder.withPayload(mediaFile).build();
        SendResult syncSend = rocketMQTemplate.syncSend("media-file-topic:media-push-tag", fileMessage);
        SendStatus sendStatus = syncSend.getSendStatus();
        return sendStatus.equals(SendStatus.SEND_OK)?true:false;
    }
}
